/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.blog.wordpress.entities.managedbeans;

import com.blog.wordpress.entities.Article;
import com.blog.wordpress.sessionbeans.ArticleFacadeLocal;
import java.util.List;
import javax.annotation.ManagedBean;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;

/**
 *
 * @author Breath
 */
@ManagedBean
@RequestScoped
public class ArticleBean {

    List<Article> articles;
    Article article = new Article();
    @EJB
    ArticleFacadeLocal articleFacade;
    

    public Article getArticle() {
        return article;
    }

    public void setArticle(Article article) {
        this.article = article;
    }

    public ArticleFacadeLocal getArticleFacade() {
        return articleFacade;
    }

    public void setArticleFacade(ArticleFacadeLocal articleFacade) {
        this.articleFacade = articleFacade;
    }

    public List<Article> getArticles() {
        return articles;
    }

    public void setArticles(List<Article> articles) {
        this.articles = articles;
    }

    public String persistArticle() {
        if (article != null) {
            articleFacade.create(article);
        }
        return "showRegMenu";
    }

    public void editArticle() {
        if (article != null) {
            articleFacade.edit(article);
        }
    }

    public void removeArticle() {
        if (article != null) {
            articleFacade.remove(article);
        }
    }

    public int convertId(String id) {
        if (id.equals("")) {
            return 1;
        }
        return Integer.parseInt(id);
    }
}
